/**
 * @File name: driver/device.h
 * @Synopsis:
 * @Author: xing.dai@aliyun.com
 * @Version: 0.0.1
 * @Date: 2018-08-27 16:51
 */

#ifndef __DEVICE_H__
#define __DEVICE_H__

#include "object.h"

//#define DEVICE_NAME_MAX_LEN		15

typedef enum {
    DEVICE_CLASS_CHAR = 0,
    DEIVCE_CLASS_BLOCK,
    DEVICE_CLASS_NET,
} device_class_type;

typedef struct _device {
    object_t object;
    uint32 type;
    uint32 flag;
    uint16 open_flag;
    uint8  count;
    uint8  device_id;
    /* device call back */
    int (*rx_indicate)(struct _device *device, uint32 size);
    int (*tx_complete)(struct _device *device, void *buffer);
    /* common device interface */
    int (*init)		(struct _device *device);
    int (*open)		(struct _device *device, uint32 oflag);
    int (*close)	(struct _device *device);
    uint32 (*read)	(struct _device *device, int32 pos, void *buffer, int32 length);
    uint32 (*write)	(struct _device *device, int32 pos, void *buffer, int32 length);
    int (*control)	(struct _device *device, uint8 cmd, void *args);
    /* device private data */
    void *private;
} device_t;

int device_register(device_t *device, char *name, uint32 flag);
int device_tree_init(void);
device_t *device_find(const char *name);

int device_init(device_t *device);
int device_open(device_t *device, uint32 flag);
int device_close(device_t *device);
uint32 device_read(device_t *device, int pos, void *buffer, uint32 size);
uint32 device_write(device_t *device, int pos, void *buffer, uint32 size);
int device_control(device_t *device, uint8 cmd, void *arg);

#endif

